package com.team.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.team.entity.Patient;
import com.team.service.PatientService;
import com.team.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/patient")
public class PatientController {
    @Autowired
    private PatientService patientService;
    @RequestMapping("/addPatient")
    @ResponseBody
    public Result<Patient> addPatient(@RequestBody Patient patient){
        int temp=patientService.addPatient(patient);
        if (temp>0){
            return new Result<>("1000","添加成功",patient);
        }else {
            return new Result<>("1001","添加失败",null);
        }
    }
    @RequestMapping("/getPatientByIdCard")
    @ResponseBody
    public Result<Patient> getPatientByIdCard(@RequestParam("idCard") String idCard){
        Patient patient= patientService.getPatientById(idCard);
        return new Result<>("1000","查询成功",patient);
    }
    @RequestMapping("/confirmMedicare")
    @ResponseBody
    public Result<String> confirmMedicare(@RequestParam("idCard") String idCard){
        String temp=patientService.hasMedicare(idCard);
        if (temp!=null&&!temp.equals("")){
            return new Result("1000","存在该医保卡",temp);
        }else {
            return new Result("1001","您没有该医保卡",temp);
        }
    }
    @RequestMapping("/getPatientBySickroomId")
    @ResponseBody
    public Result<List<Patient>> getPatientBySickroomId(Integer sickroomId){
        List<Patient> patientList=patientService.getPatientBySickroomId(sickroomId);
        return new Result<>("200","查询成功",patientList);
    }
    @RequestMapping("/out")
    @ResponseBody
    public Result PatientOut(Integer id){
        int temp=patientService.patientOut(id);
        if (temp>0){
            return new Result<>("1000","出院成功");
        }else {
            return new Result<>("1001","出院失败");
        }
    }
}
